package com.sskj.fabi.http;


import com.lzy.okgo.OkGo;
import com.lzy.okgo.request.GetRequest;
import com.lzy.okgo.request.PostRequest;
import com.sskj.common.base.HttpData;
import com.sskj.fabi.bean.BuySellBean;
import com.sskj.fabi.bean.OrderDetailBean;
import com.sskj.fabi.bean.PayTypeResultBean;
import com.sskj.fabi.bean.PublishRecordBean;
import com.sskj.lib.bean.PageBean;
import com.sskj.lib.util.CommonUtil;

/**
 * 作者 :吕志豪
 * 简书：https://www.jianshu.com/u/6e525b929aac
 * github：https://github.com/lvzhihao100
 * 描述：
 * 创建时间：2018-10-15 14:08
 */
public class HttpService {


    public GetRequest<HttpData<PageBean<BuySellBean>>> getSellBuy(String page, String pageSize, boolean isBuy) {
        return OkGo.<HttpData<PageBean<BuySellBean>>>get(HttpConfig.BASE_URL + HttpConfig.FABI_BUY_SELL)
                .params("type", isBuy ? "2" : "1")
                .params("page", page)
                .params("size", pageSize);
    }


    public PostRequest<HttpData<OrderDetailBean>> order(String tpwd, String order_no, String total_num, String total_price, boolean isBuy) {
        return OkGo.<HttpData<OrderDetailBean>>post(HttpConfig.BASE_URL + HttpConfig.FABI_CREATE_ORDER)
                .params("payment_password", CommonUtil.getFiveMd5Value(tpwd))
                .params("order_no", order_no)
                .params("total_num", total_num)
                .params("total_price", total_price)
                .params("type", isBuy ? 1 : 2);

    }

    public PostRequest<HttpData<PayTypeResultBean>> getPayWayList() {
        return OkGo.<HttpData<PayTypeResultBean>>post(HttpConfig.BASE_URL + HttpConfig.FABI_PAY_WAY_LIST);
    }

    public PostRequest<HttpData> fabiPublish(boolean isBuy, String sumCount, String lowCount, String hightCount, String unitPrice, int payWx, int payAli, int payBank, String remark, String pwd) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.FABI_PUBLISH)
                .params("trans_num", sumCount)
                .params("min_price", lowCount)
                .params("max_price", hightCount)
                .params("price", unitPrice)
                .params("pay_wx", payWx)
                .params("pay_alipay", payAli)
                .params("pay_backcard", payBank)
//                .params("pay_password", CommonUtil.getFiveMd5Value(pwd))
                .params("payment_password", CommonUtil.getFiveMd5Value(pwd))
                .params("notes", remark)
                .params("type", isBuy ? "pmma" : "sell");
    }

    public GetRequest<HttpData<PageBean<PublishRecordBean>>> getPublishRecord(String page, String pageSize, boolean isBuy) {
        return OkGo.<HttpData<PageBean<PublishRecordBean>>>get(HttpConfig.BASE_URL + HttpConfig.FABI_PUBLISH_RECORD)
                .params("type", isBuy ? "pmma" : "sell")
                .params("page", page)
                .params("size", pageSize);
    }

    /**
     * 撤单
     */
    public PostRequest<HttpData> cancelPublishOrder(boolean isBuy, String id) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.FABI_PUBLISH_ORDER_CANCEL)
                .params("id", id)
                .params("type", isBuy ? "pmma" : "sell");
    }

    public GetRequest<HttpData<OrderDetailBean>> getOrderRecordInfo(String orderNum) {
        return OkGo.<HttpData<OrderDetailBean>>get(HttpConfig.BASE_URL + HttpConfig.FABI_ORDER_RECORD_INFO)
                .params("order_num", orderNum);
    }

    public PostRequest<HttpData> markPay(String orderNum) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.FABI_ORDER_MARK_PAY)
                .params("order_num", orderNum);
    }

    public PostRequest<HttpData> cancelOrder(String orderNum) {

        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.FABI_ORDER_CANCLE)
                .params("order_num", orderNum);
    }

    public PostRequest<HttpData> allegeOrder(String orderNum, String refer, String shop_account, String ss_type, String ss_reason) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.FABI_ORDER_ALLEGE)
                .params("order_num", orderNum)
                .params("refer", refer)
                .params("shop_account", shop_account)
                .params("ss_type", ss_type)
                .params("ss_reason", ss_reason);
    }

    public PostRequest<HttpData> letGo(String orderNum, String pwd) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.FABI_ORDER_LET_GO)
                .params("order_num", orderNum)
                .params("payment_password", CommonUtil.getFiveMd5Value(pwd));
    }

    public PostRequest<HttpData> cancelShop() {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.FABI_CANCEL_SHOP)
                ;
    }
}